/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
package org.springblade.modules.admin.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import lombok.AllArgsConstructor;
import javax.validation.Valid;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springblade.modules.admin.dto.SaveElevatorStructureRelationDTO;
import org.springblade.modules.admin.vo.RelationElevatorListVO;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestParam;
import org.springblade.modules.admin.entity.ElevatorPartsStructureTemplateRelation;
import org.springblade.modules.admin.vo.ElevatorPartsStructureTemplateRelationVO;
import org.springblade.modules.admin.wrapper.ElevatorPartsStructureTemplateRelationWrapper;
import org.springblade.modules.admin.service.IElevatorPartsStructureTemplateRelationService;
import org.springblade.core.boot.ctrl.BladeController;

import java.util.List;

/**
 * 电梯配件结构模板关联 控制器
 *
 * @author ysq
 * @since 2024-09-04
 */
@RestController
@AllArgsConstructor
@RequestMapping("admin/elevator/parts/structure/template/relation")
@Api(value = "电梯配件结构模板关联", tags = "电梯配件结构模板关联接口")
public class ElevatorPartsStructureTemplateRelationController extends BladeController {

	private final IElevatorPartsStructureTemplateRelationService elevatorPartsStructureTemplateRelationService;

	/**
	 * 详情
	 */
	@GetMapping("/detail")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "详情")
	public R<ElevatorPartsStructureTemplateRelationVO> detail(@RequestParam Long elevatorId) {
		ElevatorPartsStructureTemplateRelation detail = elevatorPartsStructureTemplateRelationService.getOne(Wrappers.<ElevatorPartsStructureTemplateRelation>lambdaQuery().eq(ElevatorPartsStructureTemplateRelation::getElevatorId, elevatorId), false);
		if (detail == null) {
			return R.data(null);
		}
		return R.data(ElevatorPartsStructureTemplateRelationWrapper.build().entityVO(detail));
	}


	/**
	 * 新增 电梯配件结构模板关联
	 */
	@PostMapping("/save")
	@ApiOperationSupport(order = 4)
	@ApiOperation(value = "新增")
	public R save(@Valid @RequestBody SaveElevatorStructureRelationDTO param) {
		return R.status(elevatorPartsStructureTemplateRelationService.customSave(param));
	}

	/**
	 * 修改 电梯配件结构模板关联
	 */
	@PostMapping("/customSaveOrEdit")
	@ApiOperationSupport(order = 5)
	@ApiOperation(value = "修改")
	public R customSaveOrEdit(@Valid @RequestBody ElevatorPartsStructureTemplateRelation elevatorPartsStructureTemplateRelation) {
		return R.status(elevatorPartsStructureTemplateRelationService.customSaveOrEdit(elevatorPartsStructureTemplateRelation));
	}

	/**
	 * 电梯结构模板取消关联
	 */
	@PostMapping("/remove/relation")
	@ApiOperationSupport(order = 6)
	@ApiOperation(value = "电梯结构模板取消关联")
	public R removeRelation(@ApiParam(value = "relationIds集合", required = true) @RequestParam String ids) {
		return R.status(elevatorPartsStructureTemplateRelationService.removeRelation(Func.toLongList(ids)));
	}


	@GetMapping("/getRelationElevatorList")
	@ApiOperationSupport(order = 7)
	@ApiOperation(value = "获取电梯配件结构模板关联电梯列表")
	public R<List<RelationElevatorListVO>> getRelationElevatorList(@ApiParam(value = "结构模板id", required = true) @RequestParam Long structureTemplateId) {
		return R.data(elevatorPartsStructureTemplateRelationService.getRelationElevatorList(structureTemplateId));
	}

}
